package com.example.demo.utils.http;//package com.scwl.daiyu.base.http;
//
//
//import androidx.annotation.NonNull;
//import androidx.annotation.Nullable;
//
//import com.liulishuo.okdownload.DownloadTask;
//import com.liulishuo.okdownload.SpeedCalculator;
//import com.liulishuo.okdownload.core.breakpoint.BlockInfo;
//import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo;
//import com.liulishuo.okdownload.core.cause.EndCause;
//import com.liulishuo.okdownload.core.listener.DownloadListener4WithSpeed;
//import com.liulishuo.okdownload.core.listener.assist.Listener4SpeedAssistExtend;
//import com.vector.update_app.HttpManager;
//import com.wz.wmqhelper.utils.MyLog;
//
//import java.util.List;
//import java.util.Map;
//
//import io.reactivex.Observer;
//import io.reactivex.android.schedulers.AndroidSchedulers;
//import io.reactivex.disposables.Disposable;
//import io.reactivex.schedulers.Schedulers;
//import okhttp3.ResponseBody;
//
///**
// * 使用OkGo实现接口
// */
//
//public class OkGoUpdateHttpUtil implements HttpManager {
//    /**
//     * 异步get
//     *
//     * @param url      get请求地址
//     * @param params   get参数
//     * @param callBack 回调
//     */
//    @Override
//    public void asyncGet(@NonNull String url, @NonNull Map<String, String> params, @NonNull final HttpManager.Callback callBack) {
////        OkGo.<String>get(url).params(params).execute(new com.lzy.okgo.callback.StringCallback() {
////            @Override
////            public void onSuccess(com.lzy.okgo.model.Response<String> response) {
////                callBack.onResponse(response.body());
////            }
////
////            @Override
////            public void onError(com.lzy.okgo.model.Response<String> response) {
////                super.onError(response);
////                callBack.onError("异常");
////            }
////        });
//    }
//
//    /**
//     * 异步post
//     *
//     * @param url      post请求地址
//     * @param params   post请求参数
//     * @param callBack 回调
//     */
//    @Override
//    public void asyncPost(@NonNull String url, @NonNull Map<String, String> params, @NonNull final HttpManager.Callback callBack) {
//        IHttpApiService service = HttpClient.getInstance().create(IHttpApiService.class);
//        service.getStrdata(url, params)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Observer<ResponseBody>() {
//                    @Override
//                    public void onSubscribe(Disposable d) {
//                        MyLog.e("http", "onSubscribe");
//                    }
//
//                    @Override
//                    public void onNext(ResponseBody responseBody) {
//                        try {
//                            String body = responseBody.string();
//                            callBack.onResponse(body);
//                        } catch (Exception e) {
//                            callBack.onError("请求异常");
//                            e.printStackTrace();
//                        }
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        MyLog.e("http", "" + e.getMessage());
//                        callBack.onError("请求错误");
//                    }
//
//                    @Override
//                    public void onComplete() {
//                        MyLog.e("http", "onComplete");
//                    }
//                });
//    }
//
//    /**
//     * 下载
//     *
//     * @param url      下载地址
//     * @param path     文件保存路径
//     * @param fileName 文件名称
//     * @param callback 回调
//     */
//    @Override
//    public void download(@NonNull String url, @NonNull String path, @NonNull String fileName, @NonNull final HttpManager.FileCallback callback) {
//
//        DownloadTask task = new DownloadTask.Builder(url, path, fileName)
//                .setFilename(fileName)
//                // the minimal interval millisecond for callback progress
//                .setMinIntervalMillisCallbackProcess(30)
//                // do re-download even if the task has already been completed in the past.
//                .setPassIfAlreadyCompleted(false)
//                .build();
//
////        task.enqueue(listener);
////
////// cancel
////        task.cancel();
////
////// execute task synchronized
//        task.enqueue(new DownloadListener4WithSpeed() {
//                         private long totalLength;
//
//                         @Override
//                         public void infoReady(@NonNull DownloadTask task, @NonNull BreakpointInfo info, boolean fromBreakpoint, @NonNull Listener4SpeedAssistExtend.Listener4SpeedModel model) {
//                             MyLog.e("DownloadListener", "infoReady " + info.getTotalLength());
//                             totalLength = info.getTotalLength();
//                             callback.onBefore();
//                         }
//
//                         @Override
//                         public void progressBlock(@NonNull DownloadTask task, int blockIndex, long currentBlockOffset, @NonNull SpeedCalculator blockSpeed) {
//                             MyLog.e("DownloadListener", "progressBlock");
//                         }
//
//                         @Override
//                         public void progress(@NonNull DownloadTask task, long currentOffset, @NonNull SpeedCalculator taskSpeed) {
//                             MyLog.e("DownloadListener", "progress  " + currentOffset + "----" + totalLength);
//                             float progress = currentOffset / (float) totalLength;
//                             MyLog.e("DownloadListener", "progress ~~~~~ " + progress + "   " + (currentOffset / totalLength));
//                             callback.onProgress(progress, totalLength);
//                         }
//
//                         @Override
//                         public void blockEnd(@NonNull DownloadTask task, int blockIndex, BlockInfo info, @NonNull SpeedCalculator blockSpeed) {
//                             MyLog.e("DownloadListener", "blockEnd");
//                         }
//
//                         @Override
//                         public void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause, @Nullable Exception realCause, @NonNull SpeedCalculator taskSpeed) {
//                             MyLog.e("DownloadListener", "taskEnd");
//                             if (realCause != null) {
//                                 callback.onError("异常" + realCause.getMessage());
//                             } else {
//                                 callback.onResponse(task.getFile());
//                             }
//                         }
//
//                         @Override
//                         public void taskStart(@NonNull DownloadTask task) {
//                             MyLog.e("DownloadListener", "taskStart");
//                         }
//
//                         @Override
//                         public void connectStart(@NonNull DownloadTask task, int blockIndex, @NonNull Map<String, List<String>> requestHeaderFields) {
//                             MyLog.e("DownloadListener", "connectStart");
//                         }
//
//                         @Override
//                         public void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode, @NonNull Map<String, List<String>> responseHeaderFields) {
//                             MyLog.e("DownloadListener", "connectEnd");
//                         }
//                     }
//        );
////            @Override
////            public void taskStart(@NonNull DownloadTask task) {
////                MyLog.e("DownloadListener", "taskStart");
////            }
////
////            @Override
////            public void connectTrialStart(@NonNull DownloadTask task, @NonNull Map<String, List<String>> requestHeaderFields) {
////                MyLog.e("DownloadListener", "connectTrialStart");
////            }
////
////            @Override
////            public void connectTrialEnd(@NonNull DownloadTask task, int responseCode, @NonNull Map<String, List<String>> responseHeaderFields) {
////                MyLog.e("DownloadListener", "connectTrialEnd" + responseCode);
////            }
////
////            @Override
////            public void downloadFromBeginning(@NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull ResumeFailedCause cause) {
////                MyLog.e("DownloadListener", "downloadFromBeginning");
////            }
////
////            @Override
////            public void downloadFromBreakpoint(@NonNull DownloadTask task, @NonNull BreakpointInfo info) {
////                MyLog.e("DownloadListener", "downloadFromBreakpoint");
////            }
////
////            @Override
////            public void connectStart(@NonNull DownloadTask task, int blockIndex, @NonNull Map<String, List<String>> requestHeaderFields) {
////                MyLog.e("DownloadListener", "connectStart " + blockIndex);
////            }
////
////            @Override
////            public void connectEnd(@NonNull DownloadTask task, int blockIndex, int responseCode, @NonNull Map<String, List<String>> responseHeaderFields) {
////                MyLog.e("DownloadListener", "connectEnd " + blockIndex);
////            }
////
////            @Override
////            public void fetchStart(@NonNull DownloadTask task, int blockIndex, long contentLength) {
////                MyLog.e("DownloadListener", "fetchStart " + blockIndex + "~~~" + contentLength);
////                callback.onBefore();
////                callback.onProgress(blockIndex, contentLength);
////            }
////
////            @Override
////            public void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes) {
////                MyLog.e("DownloadListener", "fetchProgress " + blockIndex + "~~~" + increaseBytes);
////                callback.onProgress(blockIndex, increaseBytes);
////            }
////
////            @Override
////            public void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength) {
////                MyLog.e("DownloadListener", "fetchEnd " + blockIndex + "~~~" + contentLength);
////
////            }
////
////            @Override
////            public void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause, @Nullable Exception realCause) {
////                MyLog.e("DownloadListener", "taskEnd ");
////                if (realCause != null) {
////                    callback.onError("异常" + realCause.getMessage());
////                } else {
////                    callback.onResponse(task.getFile());
////                }
////            }
////        }
//    }
//}